/*
 * Queue.h
 *
 *  Created on: 07.01.2013
 *      Author: Michael
 */

#ifndef QUEUE_H_
#define QUEUE_H_

#include <list>
#include <iostream>
using namespace std;

// TEMPLATED METHODS HAVE TO BE IN THE HEADER FILE
// The compiler must have access to the implementations of templated functions at the points where they're instantiated!
// Otherwise you'll get an undefined reference error for the methods using templates

template<class T>
class Queue {
private:
	list<T> _list;
	typename list<T>::iterator _it;

public:
	/**
	 * Create a new queue.
	 */
	Queue() {
		_it = _list.begin();
	}

	/*
	 * Destructor
	 */
	~Queue() {

	}

	/**
	 * Put an object into the queue.
	 * obj: The object to enqueue
	 */
	void enqueue(const T& obj) {
		_list.insert(_list.end(), obj);
	}

	/**
	 * Get the next object from the queue.
	 */
	T& dequeue() {
		typename list<T>::iterator first = _list.begin();
		_list.erase(first);
		return *first;
	}

	/**
	 * Get the size of the queue.
	 */
	int size() {
		return _list.size();
	}

	/**
	 * Check if the queue is empty.
	 */
	bool isEmpty(){
		return size() == 0;
	}

	/**
	 * Print the queue.
	 */
	void print() {
		for (typename list<T>::iterator it = _list.begin(); it != _list.end();
				++it) {
			std::cout << ' ' << *it;
			std::cout << '\n';
		}

		std::cout << "------\n";
	}
};

#endif /* QUEUE_H_ */
